export const tags = {
  namespaced: true, // 为了解决不同模块的属性和方法命名冲突的问题
  state: {
    activePath: "welcome",
    cachePageList: ["Welcome"],
    tagList: [{ authName: "首页", path: "welcome", componentName: "Welcome" }],
  },
  getters: {},
  mutations: {
    //清空tagList中的数据
    clearTags(state) {
      state.activePath = "welcome";
      state.cachePageList = ["Welcome"];
      state.tagList = [{ authName: "首页", path: "welcome", componentName: "Welcome" }];
    },
    //点击菜单跳转页面的时候执行
    selectMenu(state, itemMenu) {
      //当前选中的菜单
      const activePath = itemMenu.path;
      //判断是否包含选中的菜单
      const result = state.tagList.some((p) => p.path == activePath);
      //不包含,就添加进来
      if (!result) {
        state.tagList.push({
          authName: itemMenu.authName,
          path: itemMenu.path,
        });
      }
      state.activePath = activePath;
    },
    //添加keepalive缓存
    addKeepAliveCache(state, val) {
      //不存在就添加缓存
      if (state.cachePageList.indexOf(val) === -1) state.cachePageList.push(val);
    },
    //删除keepalive缓存
    removeKeepAliveCache(state, val) {
      //存在就删除
      const index = state.cachePageList.indexOf(val);
      if (index !== -1) {
        state.cachePageList.splice(index, 1);
      }
    },
    closeTag(state, item) {
      state.activePath = item.activePath;
      state.tagList = item.tagList;
    },
    //更改activePath活跃路径
    changMenu(state, path) {
      state.activePath = path;
    },
  },
  actions: {},
  modules: {},
};
